/*
https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/submissions/562216035/
LC2024. 考试的最大困扰度
*/
class Solution {
public:
    int maxConsecutiveAnswers(string answerKey, int k) {
        int len=-1,l=0,n=answerKey.size();
        int mp[2]={0};
        for(int r=0;r<n;++r){
            if(answerKey[r]=='T') ++mp[0];
            else ++mp[1];
            while(mp[0]>k&&mp[1]>k){
                if(answerKey[l]=='T') --mp[0];
                else --mp[1];
                ++l;
            }
            len=max(len,r-l+1);
        }
        return len;
    }
};